import numpy as np


# data[i][j]表示第i个样本的第j个指标得分
# 通过读入不同附件的数据来计算出不同的预测结果
data = [
    [2.3, 6.4, 4.3, 5.4, 12.2, 2.9, 4.5, 5.2, 11.8, 7.7],
    [2.9, 7.2, 4.5, 6.5, 13, 4.7, 6.8, 6.7, 18.4, 9.6],
    [3.4, 8.6, 4.7, 6.2, 13.2, 4.7, 6.2, 6.7, 17.3, 9.4],
    [4, 8, 3.4, 4.7, 11.2, 3.4, 5.4, 5.6, 14.5, 8.4],
    [4.3, 8.4, 4.5, 5.9, 12.6, 4, 4.9, 5.3, 14.8, 8.6],
    [3.9, 7, 4.5, 6, 12.2, 3.6, 5.3, 6, 15.1, 8.6],
    [4, 5.8, 4.2, 5.7, 11.6, 4.3, 5.5, 6.1, 15.4, 8.9],
    [2.7, 7, 4.7, 6.4, 13.6, 3.7, 5.8, 5.8, 14.2, 8.4],
    [3.1, 7.4, 5.5, 7.3, 14.4, 4.7, 6.4, 6.4, 16.6, 9.7],
    [4, 6.8, 4.7, 6.2, 12.6, 4.1, 5.7, 5.9, 15.4, 8.8],
    [4, 4.6, 4.4, 6.4, 12.6, 3.9, 5.7, 5.9, 14.2, 8.4],
    [1.1, 4, 2.7, 4.2, 9, 2.8, 4.5, 5, 12.7, 7.9],
    [2.6, 7.6, 4.6, 5.8, 12.8, 4.3, 5.9, 6.1, 16, 8.9],
    [3.7, 8.2, 4, 4.8, 11.6, 4, 5.8, 5.9, 16.3, 8.7],
    [3.9, 7.6, 2.4, 4, 9, 2.9, 3.9, 5, 12.4, 7.6],
    [3.1, 7.4, 4.7, 6, 12.6, 4.2, 6.1, 6, 15.7, 9.1],
    [3.9, 7.8, 4.8, 5.9, 12.8, 4.7, 6.6, 6.4, 17.2, 9.2],
    [1.89, 5, 2.9, 5.1, 10, 3.3, 5, 5.4, 13.6, 7.9],
    [3.9, 8, 4.6, 6.4, 13, 4.2, 6.5, 6.5, 16.3, 9.2],
    [3.7, 6.22, 5.2, 7.3, 14, 4.4, 6.4, 6.2, 16.6, 9.2],
    [3.5, 8, 4.4, 6.4, 12.2, 4.2, 6.3, 6, 16.9, 9.2],
    [3.9, 8, 4.5, 6.7, 12.8, 4.6, 6.2, 5.8, 15.7, 9 ],
    [3.2, 8.2, 5.3, 7.4, 14.6, 4.8, 7, 7, 18.1, 10],
    [4.1, 8, 4.5, 6.6, 12.6, 4.3, 6.3, 5.9, 16.6, 9.1],
    [4, 6.4, 4.4, 5.3, 12, 4.1, 4.9, 5.6, 14.2, 8.3],
    [3.6, 7.8, 4.7, 6, 12.8, 4.1, 5.4, 5.7, 14.8, 8.9],
    [3.7, 6.2, 4.2, 5.6, 11.8, 4.4, 6, 6.1, 16, 9]
]
# 归一化处理
pre_data = np.zeros(shape=(27, 10))
for i in range(27):
    for j in range(10):
        pre_data[i][j] = (data[i][j] - np.min(data, axis=0)[j]) / (np.max(data, axis=0)[j] - np.min(data, axis=0)[j])

# 计算比重
p = np.zeros(shape=(27, 10))
for i in range(27):
    for j in range(10):
        p[i][j] = pre_data[i][j] / np.sum(pre_data, axis=0)[j]

# 计算每个指标的信息熵
e = np.zeros(shape=(10, 1))
K = 1 / np.log(27)
for j in range(10):
    e[j] = -K * np.sum([pi * np.log(pi) if pi != 0 else 0 for pi in p[j]])

# 计算每个指标的权重
omega = np.zeros(shape=(10, 1))
for j in range(10):
    omega[j] = (1 - e[j]) / (np.sum([(1 - ei) for ei in e]))

# 计算评分
y = np.zeros(shape=(27, 1))
for i in range(27):
    y[i] = np.sum([xij * oj * 100 for (xij, oj) in zip(pre_data[i], omega)])

res = {}
for index, f in enumerate(y):
    if f[0] > 90:
        res["酒样品" + str(index + 1)] = "分数：" + str(f[0]) + " 等级：" + 'A'
    elif f[0] > 75:
        res["酒样品" + str(index + 1)] = "分数：" + str(f[0]) + " 等级：" + 'B'
    elif f[0] > 60:
        res["酒样品" + str(index + 1)] = "分数：" + str(f[0]) + " 等级：" + 'C'
    elif f[0] > 40:
        res["酒样品" + str(index + 1)] = "分数：" + str(f[0]) + " 等级：" + 'D'
    else:
        res["酒样品" + str(index + 1)] = "分数：" + str(f[0]) + " 等级：" + 'E'

for i in range(27):
    print("%-5s %10s" % ("酒样品" + str(i + 1), res["酒样品" + str(i + 1)]))
